extends "../mittbase/mittbase.gd"
var cnt = 0
var cnt2 = 0
var flag = 0
var flag2 = 0
var norc = 0
func init():
	.init()
	name = "抓取手套"
	resetdata()
	att.maxHp = 50
	att.atk = 20
	att.def = 12
	att.mgiDef = 12
	info = "虚空抓取：开局将距离自身最远的敌人拉到自身附近(可失败），并眩晕2s（必中）\n"

func _connect():
	._connect()
	masCha.connect("onBattleStart",self,"xkzq")
	sys.main.connect("onBattleStart",self,"resetcnt")

func resetcnt():
	cnt = 0
	norc = 0
	flag = 0
	flag2 = 0
	cnt2 = 0
	if self.id != "i_TD_mitt":
		xkhd()

func xkzq():
	var chas = masCha.getAllChas(1)
	chas.sort_custom(self,"sort")
	if self.id != "i_TD_mitt1_Hide_MAX":
		chas[0].jump(masCha,chas[0])
		chas[0].addBuff(ctrl.b_xuanyun.new(1))
	else:
		var cell = masCha.cell
		masCha.jump(chas[0],masCha)
		yield(sys.get_tree().create_timer(0.01),"timeout")
		if masCha.cell != cell:
			chas = masCha.getCellChas(masCha.cell,masCha.att.atkRan,1)
			for i in chas:
				i.addBuff(ctrl.b_xuanyun.new(1))
				masCha.hurtChara(i,masCha.att.atk*0.88,Chara.HurtType.PHY,Chara.AtkType.SKILL)
			masCha.addBuff(ctrl.b_xuanyun.new(1))
			masCha.addBuff(JM.new(1))


func sort(a,b):
	var x1 = abs(a.cell.x - masCha.cell.x)
	var x2 = abs(b.cell.x - masCha.cell.x)
	var y1 = abs(a.cell.y - masCha.cell.y)
	var y2 = abs(b.cell.y - masCha.cell.y)
	return (x1*x1 + y1*y1) > (x2*x2 + y2*y2)

func xkhd():
	var chas = masCha.getCellChas(masCha.cell,masCha.att.atkRan,2)
	for i in range(4):
		if i >= chas.size():break
		chas[i].changeShield(masCha.att.atk*0.5)
	if sys.rndPer(20):
		var dmg = masCha.att.atk * 1.2
		chas = masCha.getAllChas(1)
		chas.shuffle()
		for i in chas:
			masCha.hurtChara(i,dmg,Chara.HurtType.MGI,Chara.AtkType.SKILL)
			dmg = dmg * 0.9

class JM extends Buff:
	var canremove:bool
	func _init(lv):
		attInit()
		life = 2.0
		id = "JM"
		att.defR = 0.5